package rita.rule;

import rita.util.RitaUtilities;
import rita.util.RulesUtilities;
import codeblocks.Block;
import codeblocks.BlockConnector;
import codeblocks.LinkRule;

public class FunctionRule implements LinkRule {

	@Override
	public boolean canLink(Block block1, Block block2, BlockConnector socket1,
			BlockConnector socket2) {

		if ((RitaUtilities.isMathFunction(block2) && RitaUtilities.isArithmeticOperand(block1))) {
			// Some functions need special arrangements
			socket2.setKind(socket1.getKind());

			if (RitaUtilities.isAbsFunction(block2)) {
				block2.setPlugKind(block1.getPlugKind());
				if (block2.getPlug().hasBlock())
					RulesUtilities.checkConnectedSocketConsistency(block2);
			}

			return true;
		}

		return false;
	}	

	@Override
	public boolean isMandatory() {
		return false;
	}

}
